package com.example.stumanager.student;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.Toast;

import com.example.stumanager.HomepageLoginInterface;
import com.example.stumanager.R;
import com.example.stumanager.adapter.HolidayDestinationAdapter;
import com.example.stumanager.admin.AdminHolidayDestinationPage;
import com.example.stumanager.admin.AdminHomePage;
import com.example.stumanager.admin.AdminMessagePage;
import com.example.stumanager.admin.StudentInformationView;
import com.example.stumanager.database.AnnouncementSql;
import com.example.stumanager.database.HolidayDestinationSql;
import com.example.stumanager.database.MessageSql;
import com.example.stumanager.database.UserSql;
import com.example.stumanager.entity.HolidayDestinationEntity;
import com.example.stumanager.entity.UserEntity;

import java.util.ArrayList;
import java.util.Collections;

/**
 * 学生首页
 */
public class StudentHomePage extends AppCompatActivity {
    ListView announcementList;
    private RadioButton lateReturn, repair, message, surfTheInternet, holidayDestination, pay, personalCenter, quit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.student_home_page);
        //公告栏
        announcementList = findViewById(R.id.announcementList);




        //晚归申请
        lateReturn = findViewById(R.id.lateReturn);
        //报修
        repair = findViewById(R.id.repair);
        //留言
        message = findViewById(R.id.message);
        //上网
        surfTheInternet = findViewById(R.id.surfTheInternet);
        //假期
        holidayDestination = findViewById(R.id.holidayDestination);
        //缴费
        pay = findViewById(R.id.pay);
        //个人中心
        personalCenter = findViewById(R.id.personalCenter);
        //退出
        quit = findViewById(R.id.button1);

        lateReturn.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(StudentHomePage.this, StudentLateReturnPage.class);
            startActivity(intent);
        });

        repair.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(StudentHomePage.this, StudentRepairPage.class);
            startActivity(intent);
        });

        message.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(StudentHomePage.this, StudentMessagePage.class);
            startActivity(intent);
        });

        surfTheInternet.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(StudentHomePage.this, StudentSurfTheInternetPage.class);
            startActivity(intent);
        });

        holidayDestination.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(StudentHomePage.this, StudentHolidayDestinationPage.class);
            startActivity(intent);
        });

        pay.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(StudentHomePage.this, StudentPayPage.class);
            startActivity(intent);
        });

        personalCenter.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(StudentHomePage.this, StudentPersonalCenterPage.class);
            startActivity(intent);
        });

        quit.setOnClickListener(view -> {
            Intent intent = new Intent();
            intent.setClass(StudentHomePage.this, HomepageLoginInterface.class);
            startActivity(intent);
        });

    }

    @Override
    protected void onStart() {
        super.onStart();
        set();
    }

    void set() {
        AnnouncementSql db = new AnnouncementSql(this);
        ArrayList array = db.getAll();
        Collections.reverse(array);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(StudentHomePage.this, android.R.layout.simple_list_item_1, array);
        announcementList.setAdapter(adapter);
    }
}